import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * authorityManagementService - 租户级权限维护 - service
 * @date: 2018-7-31

 */
import request from 'utils/request';
import { CPAAS_IAM } from 'utils/config';
import { getCurrentOrganizationId, parseParameters } from 'utils/utils';
export function fetchTabList(_x) {
  return _fetchTabList.apply(this, arguments);
}

function _fetchTabList() {
  _fetchTabList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/doc-type/dimension/role/").concat(params.roleId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchTabList.apply(this, arguments);
}

export function queryCompany(_x2) {
  return _queryCompany.apply(this, arguments);
}

function _queryCompany() {
  _queryCompany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context2.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(params.roleId, "/authority-org"), {
              method: 'GET',
              query: params
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryCompany.apply(this, arguments);
}

export function updateCompany(_x3) {
  return _updateCompany.apply(this, arguments);
}

function _updateCompany() {
  _updateCompany = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context3.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(params.roleId, "/authority-org"), {
              method: 'POST',
              body: params.checkList
            }));

          case 2:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateCompany.apply(this, arguments);
}

export function queryData(_x4) {
  return _queryData.apply(this, arguments);
}

function _queryData() {
  _queryData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context4.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/authority"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _queryData.apply(this, arguments);
}

export function saveData(_x5) {
  return _saveData.apply(this, arguments);
}

function _saveData() {
  _saveData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context5.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(params.roleId, "/authority?authorityTypeCode=").concat(params.authorityTypeCode), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _saveData.apply(this, arguments);
}

export function deleteData(_x6) {
  return _deleteData.apply(this, arguments);
}

function _deleteData() {
  _deleteData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context6.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(params.roleId, "/authority"), {
              method: 'DELETE',
              body: params.deleteRows
            }));

          case 2:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _deleteData.apply(this, arguments);
}

export function changeAuthority(_x7) {
  return _changeAuthority.apply(this, arguments);
}

function _changeAuthority() {
  _changeAuthority = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context7.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(params.roleId, "/authority/exchange?exchanageroleId=").concat(params.exchanageroleId), {
              method: 'POST',
              body: params
            }));

          case 2:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _changeAuthority.apply(this, arguments);
}

export function copyAuthority(_x8) {
  return _copyAuthority.apply(this, arguments);
}

function _copyAuthority() {
  _copyAuthority = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context8.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(params.roleId, "/copy"), {
              method: 'POST',
              body: params.copyRoleIdList
            }));

          case 2:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _copyAuthority.apply(this, arguments);
}

export function queryUserInfo(_x9) {
  return _queryUserInfo.apply(this, arguments);
}

function _queryUserInfo() {
  _queryUserInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    var organizationId;
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            return _context9.abrupt("return", request("".concat(CPAAS_IAM, "/cpaas/v1/").concat(organizationId, "/role/").concat(params.roleId, "/info"), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _queryUserInfo.apply(this, arguments);
}

export function queryCompanyModalData(_x10) {
  return _queryCompanyModalData.apply(this, arguments);
}

function _queryCompanyModalData() {
  _queryCompanyModalData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context10.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/data/customers"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _queryCompanyModalData.apply(this, arguments);
}

export function querySupplierModalData(_x11) {
  return _querySupplierModalData.apply(this, arguments);
}

function _querySupplierModalData() {
  _querySupplierModalData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context11.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/data/suppliers"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _querySupplierModalData.apply(this, arguments);
}

export function queryPurorgModalData(_x12) {
  return _queryPurorgModalData.apply(this, arguments);
}

function _queryPurorgModalData() {
  _queryPurorgModalData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context12.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/data/purorgs"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _queryPurorgModalData.apply(this, arguments);
}

export function queryPuragentModalData(_x13) {
  return _queryPuragentModalData.apply(this, arguments);
}

function _queryPuragentModalData() {
  _queryPuragentModalData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee13$(_context13) {
      while (1) {
        switch (_context13.prev = _context13.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context13.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/data/puragents"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context13.stop();
        }
      }
    }, _callee13);
  }));
  return _queryPuragentModalData.apply(this, arguments);
}

export function queryPurcatModalData(_x14) {
  return _queryPurcatModalData.apply(this, arguments);
}
/**
 * queryValueListModalData
 * @param {object} params - 值集新建数据
 */

function _queryPurcatModalData() {
  _queryPurcatModalData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee14$(_context14) {
      while (1) {
        switch (_context14.prev = _context14.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context14.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/data/purcats"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context14.stop();
        }
      }
    }, _callee14);
  }));
  return _queryPurcatModalData.apply(this, arguments);
}

export function queryValueListModalData(_x15) {
  return _queryValueListModalData.apply(this, arguments);
}
/**
 * 查询值集视图
 * queryLovViewModalData
 * @param {object} params - 值集视图新建数据
 */

function _queryValueListModalData() {
  _queryValueListModalData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee15$(_context15) {
      while (1) {
        switch (_context15.prev = _context15.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context15.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/data/lovs"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context15.stop();
        }
      }
    }, _callee15);
  }));
  return _queryValueListModalData.apply(this, arguments);
}

export function queryLovViewModalData(_x16) {
  return _queryLovViewModalData.apply(this, arguments);
}
/**
 * 查询数据源
 * queryLovViewModalData
 * @param {object} params - 数据源新建数据
 */

function _queryLovViewModalData() {
  _queryLovViewModalData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee16$(_context16) {
      while (1) {
        switch (_context16.prev = _context16.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context16.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/data/lov-views"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context16.stop();
        }
      }
    }, _callee16);
  }));
  return _queryLovViewModalData.apply(this, arguments);
}

export function queryDataSourceModalData(_x17) {
  return _queryDataSourceModalData.apply(this, arguments);
}
/**
 * 查询数据组新建弹窗数据
 * queryDataGroupModalData
 * @param {object} params - 数据组新建数据
 */

function _queryDataSourceModalData() {
  _queryDataSourceModalData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee17$(_context17) {
      while (1) {
        switch (_context17.prev = _context17.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context17.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/data/datasources"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context17.stop();
        }
      }
    }, _callee17);
  }));
  return _queryDataSourceModalData.apply(this, arguments);
}

export function queryDataGroupModalData(_x18) {
  return _queryDataGroupModalData.apply(this, arguments);
}

function _queryDataGroupModalData() {
  _queryDataGroupModalData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(params) {
    var organizationId, param;
    return _regeneratorRuntime.wrap(function _callee18$(_context18) {
      while (1) {
        switch (_context18.prev = _context18.next) {
          case 0:
            organizationId = getCurrentOrganizationId();
            param = parseParameters(params);
            return _context18.abrupt("return", request("".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/role/").concat(param.roleId, "/data/data-group"), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context18.stop();
        }
      }
    }, _callee18);
  }));
  return _queryDataGroupModalData.apply(this, arguments);
}